package com.ceres.system.dao;

import com.ceres.system.pojo.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;
import tk.mybatis.mapper.common.Mapper;

@Component
public interface RoleMapper extends Mapper<Role> {

    /**
     * 检查角色是否已存在
     * @param role
     * @return
     */
    @Select("select * from t_role where role=#{role}")
    Role roleExistChecking(String role);

    /**
     * 将角色和菜单加入关联表
     * @param rid
     * @param mid
     */
    @Insert("insert into t_role_menu values(#{rid},#{mid})")
    void addRoleAndMenu(@Param("rid") Integer rid,@Param("mid") Integer mid);

    /**
     * 根据角色查询关联的用户
     * @param rid
     * @return
     */
    @Select("select * from t_user_role where rid=#{rid}")
    Integer[] findAdminByRole(Integer rid);

    /**
     * 根据角色删除关联的菜单
     * @param rid
     */
    @Delete("delete from t_role_menu where rid=#{rid}")
    void deleteMenusByRoleId(Integer rid);
}
